﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class MerchantSite
    {
        private readonly Chain.DAL.MerchantSite dal = new Chain.DAL.MerchantSite();

        public int Add(Chain.Model.MerchantSite model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.MerchantSite> DataTableToList(DataTable dt)
        {
            List<Chain.Model.MerchantSite> list = new List<Chain.Model.MerchantSite>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.MerchantSite item = new Chain.Model.MerchantSite();
                    if ((dt.Rows[i]["MerchantID"] != null) && (dt.Rows[i]["MerchantID"].ToString() != ""))
                    {
                        item.MerchantID = int.Parse(dt.Rows[i]["MerchantID"].ToString());
                    }
                    if ((dt.Rows[i]["MerchantDesc"] != null) && (dt.Rows[i]["MerchantDesc"].ToString() != ""))
                    {
                        item.MerchantDesc = dt.Rows[i]["MerchantDesc"].ToString();
                    }
                    if ((dt.Rows[i]["MerchantPhoto"] != null) && (dt.Rows[i]["MerchantPhoto"].ToString() != ""))
                    {
                        item.MerchantPhoto = dt.Rows[i]["MerchantPhoto"].ToString();
                    }
                    if ((dt.Rows[i]["MerchantRemark"] != null) && (dt.Rows[i]["MerchantRemark"].ToString() != ""))
                    {
                        item.MerchantRemark = dt.Rows[i]["MerchantRemark"].ToString();
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int MerchantID)
        {
            return this.dal.Delete(MerchantID);
        }

        public bool DeleteList(string MerchantIDlist)
        {
            return this.dal.DeleteList(MerchantIDlist);
        }

        public bool Exists(int MerchantID)
        {
            return this.dal.Exists(MerchantID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public Chain.Model.MerchantSite GetModel(int MerchantID)
        {
            return this.dal.GetModel(MerchantID);
        }

        public List<Chain.Model.MerchantSite> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.MerchantSite model)
        {
            return this.dal.Update(model);
        }
    }
}

